package com.outsourcing.bottle.ui;

import java.util.ArrayList;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.KeyEvent;

import com.outsourcing.bottle.BasicActivity;
import com.outsourcing.bottle.R;
import com.outsourcing.bottle.ui.fragment.RegisterFragment;
import com.viewpagerindicator.CirclePageIndicator;
import com.viewpagerindicator.PageIndicator;
/**
 * 
 * @author 06peng
 *
 */
public class RegisterSuccessActivity extends BasicActivity {
	
	CirclePageFragmentAdapter mAdapter;
	ViewPager mPager;
	PageIndicator mIndicator;

	@Override
	protected void onCreate(Bundle paramBundle) {
		super.onCreate(paramBundle);
		setContentView(R.layout.register_success);
		initViewpageFragment();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			return true;
		} else if (keyCode == KeyEvent.KEYCODE_HOME) {
			return true;
		} else {
			return super.onKeyDown(keyCode, event);
		}
	}
	
	private void initViewpageFragment() {
		mAdapter = new CirclePageFragmentAdapter(getSupportFragmentManager(), this);
		Bundle bundle = new Bundle();
		bundle.putInt("logo", 1);
		mAdapter.addFragment("", RegisterFragment.class, bundle);

		Bundle bundle1 = new Bundle();
		bundle1.putInt("logo", 2);
		mAdapter.addFragment("", RegisterFragment.class, bundle1);

		Bundle bundle2 = new Bundle();
		bundle2.putInt("logo", 3);
		mAdapter.addFragment("", RegisterFragment.class, bundle2);

		Bundle bundle3 = new Bundle();
		bundle3.putInt("logo", 4);
		mAdapter.addFragment("", RegisterFragment.class, bundle3);

		mPager = (ViewPager) findViewById(R.id.pager);
		mPager.setAdapter(mAdapter);

		mIndicator = (CirclePageIndicator) findViewById(R.id.indicator);
		mIndicator.setViewPager(mPager);
	}
	
	public static class CirclePageFragmentAdapter extends FragmentPagerAdapter {

    	private Context mContext;
		private final ArrayList<FragmentInfo> fragments = new ArrayList<FragmentInfo>();
		
		protected static final class FragmentInfo {
            @SuppressWarnings("unused")
			private final String tag;
            private final Class<?> clss;
            private final Bundle args;

            protected  FragmentInfo(String _tag, Class<?> _class, Bundle _args) {
                tag = _tag;
                clss = _class;
                args = _args;
            }
        }
    	
		public CirclePageFragmentAdapter(FragmentManager fm, Context context) {
			super(fm);
			this.mContext = context;
		}
		
		public void addFragment(String tag, Class<?> clss, Bundle args) {
			FragmentInfo fragmentInfo = new FragmentInfo(tag, clss, args);
			fragments.add(fragmentInfo);
		}

		@Override
		public Fragment getItem(int arg0) {
			FragmentInfo fragmentInfo = fragments.get(arg0);
			return Fragment.instantiate(mContext, fragmentInfo.clss.getName(), fragmentInfo.args);
		}

		@Override
		public int getCount() {
			return fragments.size();
		}
    }
}
